package de.jmda.gen.java.impl;

import de.jmda.gen.GeneratorException;
import de.jmda.gen.java.FieldModifiersGenerator;
import de.jmda.gen.java.FieldNameGenerator;
import de.jmda.gen.java.InitialisationGenerator;
import de.jmda.gen.java.ModifiersUtil;
import de.jmda.gen.java.DeclaredStaticFieldGenerator;
import de.jmda.gen.java.TypeNameGenerator;

public class DefaultDeclaredStaticFieldGenerator
		extends AbstractDeclaredFieldGenerator
		implements DeclaredStaticFieldGenerator
{
	public DefaultDeclaredStaticFieldGenerator(
      FieldModifiersGenerator modifiersGenerator,
      TypeNameGenerator typeNameGenerator,
      FieldNameGenerator fieldNameGenerator,
      InitialisationGenerator initialisationGenerator)
  {
	  super(
	  		modifiersGenerator,
	  		typeNameGenerator,
	  		fieldNameGenerator,
	      initialisationGenerator);
  }

	@Override
	public StringBuffer generate() throws GeneratorException
	{
		return validate(super.generate());
	}

	/**
	 * @param stringBuffer
	 * @return <code>stringBuffer</code>
	 * @throws GeneratorException if <code>stringBuffer</code> does not contain
	 *                            {@link ModifiersUtil#STATIC}
	 */
	protected StringBuffer validate(StringBuffer stringBuffer)
			throws GeneratorException
	{
		if (false == ModifiersUtil.hasStaticModifier(stringBuffer))
		{
			throw new GeneratorException(
					stringBuffer + " has to contain [" + ModifiersUtil.STATIC + "] " +
					"modifier");
		}
		
		return stringBuffer;
	}
}